//axios基础封装
import axios from 'axios'
import { useUserStore } from '@/stores/user'
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';

const httpInstance = axios.create({
    baseURL: '/api',//接口基地址
    timeout: 9000,//接口超时时间
})


// axios请求拦截器
httpInstance.interceptors.request.use(config => {

    //1.从pinia获取sessionId数据
    const userStore = useUserStore()
    //2.获取后端传递的sessionKey
    const sessionKey = userStore.userInfo
    if (sessionKey) {
        config.headers.sessionKey = `${sessionKey}`
    }
    return config
}, e => Promise.reject(e))

export default httpInstance